package com.learn.hibernatevalidator.chapter06.classlevel;

import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;

/**
 * @author: liyf
 * @create: 2025-01-15 22:12
 **/
public class ValidPassengerCountValidator implements ConstraintValidator<ValidPassengerCount, Car> {
    @Override
    public boolean isValid(Car car, ConstraintValidatorContext context) {
        if (car == null) {
            return true;
        }

        return car.getPassengers().size() <= car.getSeatCount();

    }
}
